#include <bits/stdc++.h>
using namespace std;



int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    cin >> s;
    int np = 0, nc = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'P') np++;
        if(s[i] == 'C') nc++;
    }
    if(np == 0 || nc < 3) {
        cout << 0 << '\n';
        return 0;
    }
    if(nc >= np * 2 + 1){
        cout << np << '\n';
        return 0;
    }
    
    int cp = (nc - 1) / 2;
    if(cp <= np){
        cout << cp << '\n';
    }else{
        cout << np << '\n';
    }

    return 0;
}